<%@ page import="com.Bean.Server" %>
<%@ page import="com.Bean.User" %>
<%@ page import="com.Util.DB" %>
<%@ page import="com.Util.ServerDao" %>
<%@ page import="com.Util.UserDao" %>
<%@ page import="java.util.Set" %>

<%--
  Created by IntelliJ IDEA.
  User: root
  Date: 19-6-23
  Time: 下午8:24
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    boolean istest = DB.jsptest;

    String tkid = new String();
    String username = new String();
    User user = new User();
    if (istest) {
        username = request.getParameter("u");

    } else if (session.getAttribute("username") == null) {

        response.sendRedirect("../login.jsp");
        //request.getRequestDispatcher("../login.jsp").forward(request, response);
    } else {
        username = session.getAttribute("username").toString();
    }
    user = UserDao.selectUser(username);

%>
<html>
<head>
    <title>Tickets内容</title>
    <link rel="stylesheet" href="../css/services.css">
    <script type="text/javascript" charset="utf8" src="../js/scripts.min.js"></script>
</head>
<section id="header">
    <div class="container">
        <ul class="top-nav">
            <li class="primary-action">
                <a href="../logout" class="btn">
                    注销
                </a>
            </li>
        </ul>
    </div>
</section>
<section>
    <nav id="nav" class="navbar navbar-default navbar-main" role="navigation">
        <div class="container">

            <div class="navbar-header">
                <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#primary-nav">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
            </div>

            <div class="collapse navbar-collapse" id="primary-nav">
                <ul class="nav navbar-nav">
                    <li menuitemname="Home" class="" id="Primary_Navbar-Home">
                        <a href="../index.html">
                            主页
                        </a>
                    </li>

                    <li menuitemname="Services" class="dropdown" id="Primary_Navbar-Services">
                        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                            服务
                            &nbsp;<b class="caret"></b> </a>
                        <ul class="dropdown-menu">
                            <li menuitemname="pm-addon-overview" id="Primary_Navbar-Services-pm-addon-overview">
                                <a href="./myvps.jsp">
                                    我的vps
                                </a>
                            </li>
                            <li menuitemname="My Services" id="Primary_Navbar-Services-My_Services">
                                <a href="./tickets.jsp">
                                    服务咨询
                                </a>
                            </li>
                            <li menuitemname="My Services">
                                <a href="./openticket.jsp">
                                    咨询客服
                                </a>
                            </li>

                        </ul>
                    </li>

                    <li menuitemname="Home" class="" id="Primary_Navbar-Home">
                        <a href="./ordervps.jsp">
                            购买VPS
                        </a>
                    </li>

                </ul>
            </div>
        </div>
    </nav>
</section>
<section id="main-body">
    <div class="container">
        <div class="row">
            <div class="col-md-9 pull-md-right">

                <div class="header-lined">
                    <h1>VPS
                        <small><%
                            if(user.getStaff().equals("client"))
                            {
                        %>您购买的<%
                                }
                            %>VPS</small>
                    </h1>
                    <ol class="breadcrumb">
                        <li>
                            <a href="../index.html"> 主页
                            </a></li>
                        <li>
                            <a href="#"> 服务
                            </a></li>
                        <li class="active">
                            我的VPS
                        </li>
                    </ol>
                </div>

            </div>
            <div class="col-md-3 pull-md-left sidebar">
                <div menuitemname="Client Details" class="panel panel-sidebar panel-sidebar">
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            <i class="fas fa-user"></i>&nbsp; 我的信息
                            <i class="fas fa-chevron-up panel-minimise pull-right"></i>
                        </h3>
                    </div>

                    <div class="panel-body">
                        <strong><%=user.getUsername()%>
                        </strong><br>
                        <%=user.getEmail()%><br>
                        <%=user.getFamilyname()%> <%=user.getName()%><br>

                    </div>
                    <div class="panel-footer clearfix">
                    </div>
                </div>
            </div>
            <div class="col-md-9 pull-md-right main-content">
                <link rel="stylesheet" type="text/css" href="./css/dataTables.bootstrap.css">
                <link rel="stylesheet" type="text/css" href="./css/dataTables.responsive.css">
                <script type="text/javascript" charset="utf8" src="./js/jquery.dataTables.min.js"></script>
                <script type="text/javascript" charset="utf8" src="./js/dataTables.bootstrap.min.js"></script>
                <script type="text/javascript" charset="utf8" src="./js/dataTables.responsive.min.js"></script>
                <script type="text/javascript">

                    if (typeof (buildFilterRegex) !== "function") {
                        function buildFilterRegex(filterValue) {

                            if (filterValue.indexOf('&') === -1) {
                                return '[~>]\\s*' + jQuery.fn.dataTable.util.escapeRegex(filterValue) + '\\s*[<~]';
                            } else {
                                var tempDiv = document.createElement('div');
                                tempDiv.innerHTML = filterValue;

                                return '\\s*' + jQuery.fn.dataTable.util.escapeRegex(tempDiv.innerText) + '\\s*';
                            }
                        }
                    }
                    jQuery(document).ready(function () {
                        jQuery(".view-filter-btns a").click(function (e) {
                            var filterValue = jQuery(this).find("span").not('.badge').html().trim();
                            var dataTable = jQuery('#tableTicketsList').DataTable();
                            var filterValueRegex;
                            if (jQuery(this).hasClass('active')) {
                                jQuery(this).removeClass('active');
                                jQuery(this).find("i.far.fa-dot-circle").removeClass('fa-dot-circle').addClass('fa-circle');
                                dataTable.column(2).search('').draw();
                            } else {
                                jQuery('.view-filter-btns .list-group-item').removeClass('active');
                                jQuery('i.far.fa-dot-circle').removeClass('fa-dot-circle').addClass('fa-circle');
                                jQuery(this).addClass('active');
                                jQuery(this).find(jQuery("i.far.fa-circle")).removeClass('fa-circle').addClass('fa-dot-circle');
                                filterValueRegex = buildFilterRegex(filterValue);
                                dataTable.column(2)
                                    .search(filterValueRegex, true, false, false)
                                    .draw();
                            }

                            // Prevent jumping to the top of the page
                            // when no matching tag is found.
                            e.preventDefault();
                        });
                    });
                </script>
                <script type="text/javascript">
                    var alreadyReady = false; // The ready function is being called twice on page load.
                    jQuery(document).ready(function () {
                        var table = jQuery("#tableTicketsList").DataTable({
                            "dom": '<"listtable"fit>pl', "responsive": true,
                            "oLanguage": {
                                "sEmptyTable": "No Records Found",
                                "sInfo": "Showing _START_ to _END_ of _TOTAL_ entries",
                                "sInfoEmpty": "显示 0 至 0 (总 0 项)",
                                "sInfoFiltered": "(filtered from _MAX_ total entries)",
                                "sInfoPostFix": "",
                                "sInfoThousands": ",",
                                "sLengthMenu": "Show _MENU_ entries",
                                "sLoadingRecords": "Loading...",
                                "sProcessing": "Processing...",
                                "sSearch": "",
                                "sZeroRecords": "No Records Found",
                                "oPaginate": {
                                    "sFirst": "First",
                                    "sLast": "Last",
                                    "sNext": "Next",
                                    "sPrevious": "Previous"
                                }
                            },
                            "pageLength": 10,
                            "order": [
                                [0, "asc"]
                            ],
                            "lengthMenu": [
                                [10, 25, 50, -1],
                                [10, 25, 50, "All"]
                            ],
                            "aoColumnDefs": [
                                {
                                    "bSortable": false,
                                    "aTargets": []
                                },
                                {
                                    "sType": "string",
                                    "aTargets": [2]
                                }
                            ],
                            "stateSave": true
                        });

                        // highlight remembered filter on page re-load
                        var rememberedFilterTerm = table.state().columns[2].search.search;
                        if (rememberedFilterTerm && !alreadyReady) {
                            // This should only run on the first "ready" event.
                            jQuery(".view-filter-btns a span").each(function (index) {
                                if (buildFilterRegex(jQuery(this).text().trim()) == rememberedFilterTerm) {
                                    jQuery(this).parent('a').addClass('active');
                                    jQuery(this).parent('a').find('i').removeClass('fa-circle').addClass('fa-dot-circle');
                                }
                            });
                        }
                        alreadyReady = true;
                    });
                </script>
                <script type="text/javascript">
                    jQuery(document).ready(function () {
                        var table = jQuery('#tableTicketsList').removeClass('hidden').DataTable();
                        table.order(3, 'desc');
                        table.draw();
                        jQuery('#tableLoading').addClass('hidden');
                    });
                </script>
                <div class="table-container clearfix">
                    <div id="tableTicketsList_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
                        <div class="listtable">
                            <table id="tableTicketsList" class="table table-list dataTable no-footer dtr-inline"
                                   aria-describedby="tableTicketsList_info" role="grid" style="width: 0px;">
                                <thead>
                                <tr role="row">
                                    <th class="sorting_disabled" rowspan="1" colspan="1" style="width: 0px;"
                                        aria-label="">服务器
                                    </th>
                                    <th class="sorting_asc" tabindex="0" aria-controls="tableServicesList" rowspan="1"
                                        colspan="1" style="width: 0px;"
                                        aria-label="Product/Service: activate to sort column descending"
                                        aria-sort="ascending">上次开机
                                    </th>
                                    <th class="sorting" tabindex="0" aria-controls="tableServicesList" rowspan="1"
                                        colspan="1"
                                        style="width: 0px;" aria-label="Pricing: activate to sort column ascending">ip
                                    </th>
                                    <th class="sorting_asc" tabindex="0" aria-controls="tableServicesList" rowspan="1"
                                        colspan="1" style="width: 0px;"
                                        aria-label="Status: activate to sort column ascending">状态

                                    </th>
                                    <th class="sorting" tabindex="0" aria-controls="tableServicesList" rowspan="1"
                                        colspan="1"
                                        style="width: 0px;"
                                        aria-label="Next Due Date: activate to sort column ascending">操作
                                    </th>

                                    <th class="responsive-edit-button sorting" style="width: 0px;" tabindex="0"
                                        aria-controls="tableServicesList" rowspan="1" colspan="1"
                                        aria-label=": activate to sort column ascending"></th>
                                </tr>
                                </thead>
                                <tbody>
                                    <%
                            Set<Server> serverSet= ServerDao.selectServerByUser(username);

                            for(Server server:serverSet)
                                {
                        %>
                                <tr onclick="clickableSafeRedirect(event, '../?action=<%=server.getStatus()%>&uname=<%=username%>', false)"
                                    role="row" class="odd">
                                    <td class="text-center" data-element-id="6084" data-type="service"
                                        data-domain="vm6084" tabindex="0">
                                        #<%=server.getId()%><br>
                                        <%=server.getName()%><br>
                                        <%=server.getOsname()%>
                                    </td>
                                    <td class="sorting_1"><a href="http://vm6084"
                                                             target="_blank"><%=server.getLaststart()%>
                                    </a></td>
                                    <td class="text-center"><%=server.getIpv4()%>
                                    </td>
                                    <td class="text-center">
                                        <span class="label status status-<%=server.getStatus()%>" style="width: 100px;margin: auto;">
                                                <%=server.getStatus()%>
                                    </td>
                                    <td class="text-center sorting_2">

                                        <form method="get" action="../<%
                                        if (user.getStaff().equals("staff")) {
                                        %>deleteser<%
                                        }else{
                                        %>closeserver<%
                                                }
                                            %>">
                                        <div>
                                            <input type="hidden" name="id" value="<%=server.getId()%>">
                                            <input type="hidden" name="status" value="<%
                                            if(server.getStatus().equals("closed"))
                                            {     %>active<%
                                        }else{  %>closed<%
                                            }
                                        %>">
                                            <input class="btn btn-primary" type="submit" value="<%

                                            if (user.getStaff().equals("client")) {
                                                if (server.getStatus().equals("active")) {
                                        %>关机<%
                                    } else {
                                    %>开机<%
                                        }
                                    } else {
                                    %>删除<%
                                            }
                                        %>
">
                                        </div>
                                        </form>

                                    <td class="responsive-edit-button" style="">
                                        <a href="" class="btn btn-block btn-info">
                                            Manage Product
                                        </a>
                                    </td>
                                </tr>
                                    <%
                            }
                        %>

                            </table>
                        </div>
                    </div>
                    <div class="text-center hidden" id="tableLoading">
                        <p><i class="fas fa-spinner fa-spin"></i> 加载中...</p>
                    </div>
                </div>
            </div>
            <div class="clearfix"></div>
        </div>
    </div>

</section>
</body>
</html>
